package top.fengleifeng.question;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import top.fengleifeng.util.Constants;

/**
 * @author : fengleifeng
 * @Package top.fengleifeng.question
 * @Description:
 * @date Date : 2021年02月25日 5:08 下午
 */
public class Num884两句话中的不常见单词 {

    class Solution {

        public String[] uncommonFromSentences(String A, String B) {

            String[] splitA = A.split(" ");
            String[] splitB = B.split(" ");
            List<String> list = new LinkedList<>();
            if (splitA.length == 0) {
                return splitB;
            } else if (splitB.length == 0) {
                return splitA;
            }
            List<String> listA = Arrays.asList(splitA);
            List<String> listB = Arrays.asList(splitB);
            for (int i = 0; i < splitA.length; i++) {
                boolean flag = true;
                for (int j = 0; j < splitA.length; j++) {
                    if (splitA[i].equals(splitA[j]) && i != j) {
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    if (!listB.contains(splitA[i])) {
                        list.add(splitA[i]);
                    }
                }
            }
            for (int i = 0; i < splitB.length; i++) {
                boolean flag = true;
                for (int j = 0; j < splitB.length; j++) {
                    if (splitB[i].equals(splitB[j]) && i != j) {
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    if (!listA.contains(splitB[i])) {
                        list.add(splitB[i]);
                    }
                }
            }
            String[] result = new String[list.size()];
            for (int i = 0; i < list.size(); i++) {
                result[i] = list.get(i);
            }
            return result;
        }
    }

    public static void main(String[] args) {
        String s = "apple apple ";
        String s1 = "banana";
        String[] strings = new Num884两句话中的不常见单词().new Solution().uncommonFromSentences(s, s1);
        Constants.printArr(strings);
    }
}
